package com.zanglikun.activity.util;


import java.util.HashMap;
import java.util.Map;

/**
 * Activity 执行上下文
 * 用于在多个 Activity 之间传递和共享数据
 */
public class ActivityContext {
    private final Map<String, Object> data = new HashMap<>();
    private volatile boolean shouldContinue = true;

    public void put(String key, Object value) {
        data.put(key, value);
    }

    public Object get(String key) {
        return data.get(key);
    }

    public <T> T get(String key, Class<T> type) {
        return type.cast(data.get(key));
    }

    public boolean containsKey(String key) {
        return data.containsKey(key);
    }

    public void stop() {
        this.shouldContinue = false;
    }

    public boolean isContinue() {
        return shouldContinue;
    }

    public void clear() {
        data.clear();
        shouldContinue = true;
    }
}